Filter compoud with DXL

Hi guys,
I found general problem while trying to create own filer compoud from set of filters which is defined dynamicaly.
In general user sets filter up and adds it to the Array with type Filter.
Finally I would like compoud using "and" or "or" all the requested filters to one. The problem is that I don't want to define 100 different filter names and assign the value from Array to them but use as small as possible filter variables to complete this issue. I've tried many different things unsuccessfull. E.g. notation
Filter_one = Filter_one && Filter_new after each call makes the filter compoud in this way
1st call
Filter_one = Filter_one && Filter_new
2nd call
Filter_one = Filter_one && (Filter_one && Filter_new)
3rd
Filter_one = Filter_one && (Filter_one && (Filter_one && Filter_new))
etc...
what makes final filter useless for me...
Any ideas how to force this issue?
Rafal
SystemAdmin - Wed Apr 08 06:04:09 EDT 2009

Re: Filter compoud with DXL
llandale - Wed Apr 08 13:58:33 EDT 2009

I don't deal with 'Filters', but it seems to me something like this should work:

Get the Filters and Operators from the user via GUI, store them in an Array or two.
 
Filter fInArray = null, fCompound = null
string Operator
bool   Done = false
while(!Done)
{  if (array is empty) then break
   fInArray = next filter in the stored Array
   Operator = operator associated with this Filter, also I suppose in the Array
   if (Operator == "Or")
        fCompound = fCompound or  fInArray
   elseif(Operator == "And")
        fCompound = fCompound and fInArray
   else fCompound = fCompound ! fInArray   // not sure what this means, perhaps its 'and !'.
 
   print "InLoop, InArray>Compound = " (stringOf(mod, fInArray)) "\t>" (stringOf(mod, fCompound)) "\n"
}
print "Compound = >" (stringOf(mod, fCompound)) "\n"

 


I wonder about the precedence of and/or and whether you can use parenthesis to say exactly what you want.

>Louie

 

Re: Filter compoud with DXL
SystemAdmin - Thu Apr 09 07:26:39 EDT 2009

llandale - Wed Apr 08 13:58:33 EDT 2009

I don't deal with 'Filters', but it seems to me something like this should work:

Get the Filters and Operators from the user via GUI, store them in an Array or two.
 
Filter fInArray = null, fCompound = null
string Operator
bool   Done = false
while(!Done)
{  if (array is empty) then break
   fInArray = next filter in the stored Array
   Operator = operator associated with this Filter, also I suppose in the Array
   if (Operator == "Or")
        fCompound = fCompound or  fInArray
   elseif(Operator == "And")
        fCompound = fCompound and fInArray
   else fCompound = fCompound ! fInArray   // not sure what this means, perhaps its 'and !'.
 
   print "InLoop, InArray>Compound = " (stringOf(mod, fInArray)) "\t>" (stringOf(mod, fCompound)) "\n"
}
print "Compound = >" (stringOf(mod, fCompound)) "\n"

 


I wonder about the precedence of and/or and whether you can use parenthesis to say exactly what you want.

>Louie

 

Hi,
Thanks for input. I've checked it. But unfortunatelly it doesn't work as assumed. The final results is that every call of assigment fComoud is embedded in fInArray in the same way i've posted in my previous mail...
I think there must be another way...

Re: Filter compoud with DXL
tommy3824 - Thu Apr 09 12:30:40 EDT 2009

SystemAdmin - Thu Apr 09 07:26:39 EDT 2009
Hi,
Thanks for input. I've checked it. But unfortunatelly it doesn't work as assumed. The final results is that every call of assigment fComoud is embedded in fInArray in the same way i've posted in my previous mail...
I think there must be another way...

I use a dynamic filter in one of my metrics script that reads a external CSV. I don't want to post my whole script but I can show you bits and pieces you may find useful.
First of all, I'll explain my thinking of this...

Each filter is done one at a time, so order is important.
<Module Name>,<Attribute Name>,<Value>,<Compare Type>,<Accept?>,<Combination>
The first four probably make since. Accept? is basically a inverse not (Inverts result when false) and Combination is how the previous filter is combined (ANDed or ORed) with the next. This value is arbitrary if just one filter is applied. More types can be added in very easily by just defining them.

I store all these values in multiple skip lists that all have the same key to keep them in line.

here is the main part...

for obj in mod do
{
abs = obj."Absolute Number"

re_fil = find(filterList,abs,prev) // Assigns filter_o if more than one filter

if(attrT"" == "STRING") // Test defined type
filter_o = (obj.attrN"" == attrV"")
else if(attrT"" == "INT<"") < (intOf attrV""))
else if(attrT"" == "INT>")
filter_o = ((intOf obj.attrN"") > (intOf attrV""))
else if(attrT"" == "INT=")
filter_o = ((intOf obj.attrN"") == (intOf attrV""))
else if(attrT"" == "DATE>")
{
d1 = obj.attrN""
d2 = attrV""
filter_o = (intOf d1 > intOf d2)
}
else if(attrT"" == "DATE<""
d2 = attrV""
filter_o = (intOf d1 < intOf d2)
}
else if(attrT"" == "DATE=")
{
d1 = obj.attrN
d2 = date attrV""
filter_o = (intOf d1 == intOf d2)
}
else if(attrT"" == "TEXT")
filter_o = (matches(attrV"",obj.attrN""))
else if(attrT"" == "ENUMERATION")
filter_o = (isMember(obj.attrN,attrV""))
else
filter_o = true

if(!acc_rej)
filter_o = !filter_o
if(filterType"" == "AND")
{
prev = true
re_fil = find(filterList,abs,prev) // Assigns filter_o if more than one filter
filter_o = filter_o && prev
}

else if(filterType"" == "OR")
{
prev = false
re_fil = find(filterList,abs,prev) // Assigns filter_o if more than one filter
filter_o = filter_o || prev
}

if(re_fil) // deletes old value if it exists
delete(filterList,abs)

put(filterList,abs,filter_o)

} // end for obj in mod loop

Then after the filter skip list is filled...

for filter_o in filterList do
{

abs = (int key filterList)

if(filter_o)
{
acc++
accept (object abs)
}
else
{
rej++
reject (object abs)
}
}

print m."Name"" Filtering - \tAccepted: "acc"\tRejected: "rej"\n"
delete filterList
filtering on
You should be able to do any logical combination with this (though it may not be the shortest one)